<div id="flies">
	<div id="btn_div" align="right">
		<input id="add_fly" type="button" value="Нэмэх" />
	</div>
	<table id="info" cellpadding="0" cellspacing="0">
		<thead>
			<tr id="title">
				<td>Онгоц</td>
				<td>date1</td>
				<td>date2</td>
				<td>date3</td>
				<td>date4</td>
				<td width="9px"></td>
				<td width="9px"></td>
			</tr>
		</thead>
		<tbody id="fly_list_container">{fly_list}
		</tbody>
	</table>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#add_fly").live('click', function() {
				$.ajax({
					type : "GET",
					url : "fly",
					data : "action=dialogFly",
					success : function(response) {
						$("#dialog_fly").html(response);
						$("#dialog_fly").dialog('open');
					}
				});
			});
			$("#edit_fly").live('click', function() {
				var stayId = $(this).attr('flyid');
				$.ajax({
					type : "GET",
					url : "fly",
					data : "action=dialogFly&flyid="+stayId,
					success : function(response) {
						$("#dialog_fly").html(response);
						$("#dialog_fly").dialog('open');
					}
				});
			});
			$("#delete_fly").live('click',function(){
				var stayId = $(this).attr('flyid');
				$.ajax({
					type : "GET",
					url : "fly",
					data : "action=deleteFly&flyid="+stayId,
					success : function(response) {
						if (response == 1){
							$(".fly-"+stayId).remove();
						}
					}
				});
			});
			$("#btn_save_fly").live('click',function(){
				var stayid = $("[name=dialog_stay_id]").val();
				var employee = $("[name=dialog_stay_employee]").val();
				var stayType = $("[name=dialog_stay_type]").val();
				var trainingType = $("[name=dialog_stay_training_type]").val();
				var start_date_date = $("[name=dialog_stay_start_date]").val();
				var start_date_time = $("[name=dialog_stay_start_time]").val();
				var start_date = start_date_date.trim() + " " + start_date_time.trim();
				var end_date_date = $("[name=dialog_stay_end_date]").val();
				var end_date_time = $("[name=dialog_stay_end_time]").val();
				var end_date = end_date_date.trim() + " " + end_date_time.trim();
				var location = $("[name=dialog_stay_location]").val();
				
				var data = 	"&stayid=" + stayid +
							"&employee=" + employee + 
							"&staytype=" + stayType + 
							((stayType=="TRAINING")?("&trainingtype=" + trainingType):"") + 
							"&start_date=" + start_date + 
							"&end_date=" + end_date + 
							"&location=" + location;
				
				$.ajax({
					type : "GET",
					url : "stay",
					data : "action=saveStay" + data,
					success : function(response) {
						if (response != 0){
							if (stayid == -1){
								$("#stay_list_container").html(response);
							}else{
								$('tr[stay_row="' + stayid + '"]').html(response);
							}
							$("#dialog_stay").dialog('close');
						}
					}
				});
			});
			$("#btn_cancel_fly").live('click',function(){
				$("#dialog_fly").dialog('close');
			});
		});
	</script>
</div>